package gameobj;

import manager.ElementManager;
import manager.LevelManager;

public class Boss extends Actor{
	private static ElementManager em = null;
//	将player也存入其中，方便之后跟着玩家移动
	Player player = null;
	
	public Boss() {
		// TODO 自动生成的构造函数存根
		super();
		this.setW(600);
		this.setH(200);
		this.setMaxHealth(100);
		this.setHealth(100);
		this.setDirection(false);
		this.setSpeed(3);
		if (em == null) {
			em = ElementManager.get();
		}
		this.setAttacking(true);
		this.setAttackSpeed(20);
		
		player = (Player) em.getList(ElementType.PLAYER).get(0);
		
	}

	@Override
	protected void attack() {
		// TODO 自动生成的方法存根
		Bullet bullet = new Bullet();
		bullet.setX(getX() + 30);
		bullet.setY(getY() + 60);
		bullet.setH(50);
		bullet.setW(50);
		bullet.setSpeed(6);
		bullet.setPlayerOwned(false);
		bullet.setModel(bulletModel);
//		添加进管理
		em.add(ElementType.ITEM, bullet);
	}
	
	@Override 
	protected void move() {
//		举例玩家的举例
		int xDistance = this.getX() - player.getX();
		if (xDistance > 0) {
			setX(getX() - getSpeed());
		} else if (xDistance < 0) {
			setX(getX() + getSpeed());
		}
	}
	
	@Override
	public void getHurt(int damage) {
		// TODO 自动生成的方法存根
		this.setHealth(getHealth()-damage);
		if(this.getHealth()<=0)
		{
			this.setHealth(0);
			this.death();
		}
	}
	
	@Override
	public void death ()
	{
		this.setAlive(false);
		LevelManager lm = LevelManager.get();
		lm.setRunning(false);
		lm.scoreUp(1000);
	}
}
